<?php
/**
 * Created by PhpStorm.
 * User: 秋枫雁飞
 * Date: 2019/3/27
 * Time: 13:39
 */

namespace Aiweline\Core\Helper;

class IO
{
    /**
     * [$io io操作管理器]
     * @var \Magento\Framework\Filesystem\Io\File
     */
    private $io;
    /**
     * [$directoryList 目录列表管理器]
     * @var \Magento\Framework\Filesystem\DirectoryList
     */
    private $directoryList;

    /**
     * [__construct 构造函数]
     * @param \Magento\Framework\Filesystem\Io\File $io [magento的io操作管理器]
     * @param \Magento\Framework\Filesystem\DirectoryList $DirectoryList [magento的io操作管理器]
     */
    function __construct(
        \Magento\Framework\Filesystem\Io\File $io,
        \Magento\Framework\Filesystem\DirectoryList $DirectoryList
    )
    {
        $this->io = $io;
        $this->directoryList = $DirectoryList;
    }

    /**
     * [createImagesDir 创建自定义媒体路径]
     * @param  string $module_name [模块名称]
     * @param  string $path [自定义media下的路径]
     * @return string       [返回创建的路径]
     */
    public function createImagesDir($module_name, $path)
    {
        $create_path = $this->directoryList->getPath('media') . '/' . $module_name . '/' . $path.'/'.date('Ymd', time()).'/';
        if (!file_exists($create_path)) {
            if (!$this->io->mkdir($create_path)) return false;
        }
        return $create_path;
    }
}